package com.neusmart.tongrentang.dialog;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.neusmart.common.dialog.BaseDialog;
import com.neusmart.common.effects.EffectsType;
import com.neusmart.tongrentang.R;

/**
 * 自定义对话框
 * <p/>
 * roy
 */

public class CustomAlertDialogSingleBtn extends BaseDialog implements OnClickListener {

    private TextView mTitle;
    private LinearLayout mLlContent;
    private Button mBtn;
    private OnSingleBtnClickListener listener;
    public CustomAlertDialogSingleBtn(Context context) {
        super(context);
        init();
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.custom_alert_dialog_single_button;
    }

    @Override
    protected void initView() {
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        mainView = findViewById(R.id.main);
        mTitle = (TextView) findViewById(R.id.custom_alert_dialog_title);
        mLlContent = (LinearLayout) findViewById(R.id.custom_alert_dialog_content);
        mBtn = (Button) findViewById(R.id.custom_alert_dialog_btn);
    }

    public void setTitle(CharSequence message) {
        mTitle.setText(message);
    }

    public void setTitle(int messageId) {
        mTitle.setText(messageId);
    }

    public void addContentView(View view) {
        mLlContent.addView(view);
    }

    public void setButton(CharSequence text) {
        mBtn.setText(text);
    }

    public void setButton(int textId) {
        mBtn.setText(textId);
    }

    public void setOnSingleBtnClickListenerr(OnSingleBtnClickListener l) {
        this.listener = l;
    }

    @Override
    protected void setListener() {
        super.setListener();
        mBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.custom_alert_dialog_btn:
                if (listener != null)
                    listener.onSingleBtnClick();
            default:
                break;
        }
        dismiss();
    }

    @Override
    protected EffectsType initEffectsType() {
        return null;
    }

    public interface OnSingleBtnClickListener {
        void onSingleBtnClick();
    }

}
